// pages/class-punch/class-punch.js
Page({
  data: {
    stats: {
      totalDays: 0, totalBooks: 0, todayBooks: 0, weekBooks: 0, monthBooks: 0
    },
    canPunch: false,
    calendar: [],
    currentTab: 'latest',
    punchList: []
  },
  onLoad() {
    this.loadStats();
    this.loadCalendar();
    this.loadPunchList('latest');
  },
  loadStats() {
    // TODO: 替换为API
    this.setData({
      stats: { totalDays: 12, totalBooks: 30, todayBooks: 2, weekBooks: 5, monthBooks: 10 },
      canPunch: 2 > 0
    });
  },
  loadCalendar() {
    // TODO: 替换为API
    this.setData({
      calendar: [
        { date: '07-01', hasPunched: true },
        { date: '07-02', hasPunched: false },
        { date: '07-03', hasPunched: true },
        { date: '07-04', hasPunched: true },
        { date: '07-05', hasPunched: false },
        { date: '07-06', hasPunched: true },
        { date: '07-07', hasPunched: false }
      ]
    });
  },
  loadPunchList(tab) {
    // TODO: 替换为API
    this.setData({
      currentTab: tab,
      punchList: [
        {
          punchId: 'p1', userId: 'u1', nickname: '小明', avatar: '/images/user.png',
          punchText: '今天读了3本书，收获满满！', dayCount: 5,
          bookList: [
            { bookId: 'b1', coverUrl: '/images/book.png' },
            { bookId: 'b2', coverUrl: '/images/book-cn.png' }
          ],
          isFollowed: false
        }
      ]
    });
  },
  onTabChange(e) {
    const tab = e.currentTarget.dataset.tab;
    this.loadPunchList(tab);
  },
  onPunch() {
    wx.navigateTo({ url: '/pages/punch-publish/punch-publish' });
  },
  goMethod() {
    wx.navigateTo({ url: '/pages/method/method' });
  },
  goMyRecordings() {
    wx.navigateTo({ url: '/pages/my-recordings/my-recordings' });
  },
  goEar() {
    wx.navigateTo({ url: '/pages/audio-list/audio-list' });
  },
  onBookCoverTap(e) {
    const book = e.currentTarget.dataset.book;
    wx.navigateTo({ url: `/pages/detail/detail?bookId=${book.bookId}` });
  },
  onFollow(e) {
    const userId = e.currentTarget.dataset.userid;
    // TODO: 调用关注/取消关注API并刷新
    wx.showToast({ title: '关注状态已更新', icon: 'success' });
  }
}); 